{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Average Value of Even Numbers That Are Divisible by Three"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #math"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #数学"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: averageValue"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #可被三整除的偶数的平均值"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个由正整数组成的整数数组 <code>nums</code> ，返回其中可被 <code>3</code> 整除的所有偶数的平均值。</p>\n",
    "\n",
    "<p>注意：<code>n</code> 个元素的平均值等于 <code>n</code> 个元素 <strong>求和</strong> 再除以 <code>n</code> ，结果 <strong>向下取整</strong> 到最接近的整数。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>nums = [1,3,6,10,12,15]\n",
    "<strong>输出：</strong>9\n",
    "<strong>解释：</strong>6 和 12 是可以被 3 整除的偶数。(6 + 12) / 2 = 9 。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>nums = [1,2,4,7,10]\n",
    "<strong>输出：</strong>0\n",
    "<strong>解释：</strong>不存在满足题目要求的整数，所以返回 0 。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= nums.length &lt;= 1000</code></li>\n",
    "\t<li><code>1 &lt;= nums[i] &lt;= 1000</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [average-value-of-even-numbers-that-are-divisible-by-three](https://leetcode.cn/problems/average-value-of-even-numbers-that-are-divisible-by-three/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [average-value-of-even-numbers-that-are-divisible-by-three](https://leetcode.cn/problems/average-value-of-even-numbers-that-are-divisible-by-three/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[1,3,6,10,12,15]', '[1,2,4,7,10]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        num =[x for x in nums if x % 6 ==0]\n",
    "        return 0 if len(num) ==0 else sum(num) // len(num)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        ans=i=0\n",
    "        for x in nums:\n",
    "            if x%2==0 and x%3==0:\n",
    "                ans+=x\n",
    "                i+=1\n",
    "        return ans//i if i else 0\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        list1=[]\n",
    "        result=0\n",
    "        for i in nums:\n",
    "            if i % 6 == 0:\n",
    "                list1.append(i)\n",
    "            else:\n",
    "                pass\n",
    "        if len(list1)==0:\n",
    "            return len(list1)\n",
    "        else:\n",
    "            for j in list1:\n",
    "                result+=j\n",
    "            return int(result/len(list1))\n",
    "                \n",
    "                    \n",
    "               \n",
    "                    \n",
    "            \n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        s = 0\n",
    "        l = 0\n",
    "        for n in nums:\n",
    "            if n % 6 == 0:\n",
    "                s += n\n",
    "                l += 1\n",
    "        return s//l if l else 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        s,c=0,0\n",
    "        for num in nums:\n",
    "            if num%6==0:\n",
    "                s+=num\n",
    "                c+=1\n",
    "        return 0 if c==0 else s//c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        sum = 0\n",
    "        count = 0\n",
    "        for num in nums:\n",
    "            if num % 3 == 0 and num % 2 == 0:\n",
    "                sum += num\n",
    "                count += 1\n",
    "        return 0 if count == 0 else int(sum/count)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        sum =0\n",
    "        step=0\n",
    "        for i in nums:\n",
    "            if i%6==0:\n",
    "                sum+=i\n",
    "                step+=1\n",
    "            else:\n",
    "                pass\n",
    "        if step ==0:\n",
    "            return 0\n",
    "        else:\n",
    "            return int(sum/step )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        lst = [n for n in nums if n % 6 == 0]\n",
    "        return sum(lst) // len(lst) if lst else 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        n=len(nums)\n",
    "        idx=0\n",
    "        res=0\n",
    "        for i in range(n):\n",
    "            if nums[i]%6==0:\n",
    "                res+=nums[i]\n",
    "                idx+=1\n",
    "        if idx==0: return 0\n",
    "        return res//idx"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        goal = 0\n",
    "        sumnum = 0\n",
    "        for i in nums:\n",
    "            if i % 3 == 0 and i % 2 == 0:\n",
    "                goal += i\n",
    "                sumnum += 1\n",
    "        if sumnum == 0:\n",
    "            return 0\n",
    "        return goal//sumnum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        i = 0\n",
    "        n = 0\n",
    "        for v in nums:\n",
    "            if v % 6 == 0:\n",
    "                i += v\n",
    "                n += 1\n",
    "        #return i // n if n > 0 else 0\n",
    "        return 0 if n == 0 else i // n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        ns = [x for x in nums if x % 6 == 0]\n",
    "        return 0 if len(ns) == 0 else sum(ns) // len(ns)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        s = n = 0\n",
    "        for x in nums:\n",
    "            if x % 6 == 0:\n",
    "                s += x\n",
    "                n += 1\n",
    "        return 0 if n == 0 else s // n\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        count=0\n",
    "        sum=0\n",
    "        for i in nums:\n",
    "            if i%6==0:\n",
    "                count+=1\n",
    "                sum+=i\n",
    "        if count==0:\n",
    "            return 0\n",
    "        return sum//count\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        i=0\n",
    "        while True:\n",
    "            if nums[i]%3!=0 or nums[i]%2!=0:\n",
    "                nums.pop(i)\n",
    "            else:\n",
    "                i+=1\n",
    "            if i==len(nums):\n",
    "                break\n",
    "        if len(nums)==0:\n",
    "            return 0\n",
    "        else:\n",
    "            r=int(sum(nums)/len(nums))\n",
    "            return r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        lst=[]\n",
    "        for i in range(len(nums)):\n",
    "            if nums[i]%2==0 and nums[i]%3==0:\n",
    "                lst.append(nums[i])\n",
    "        if len(lst)==0:\n",
    "            return 0\n",
    "        return sum(lst)//len(lst)\n",
    "            \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        ans = 0\n",
    "        cnt = 0\n",
    "        for nu in nums:\n",
    "            if nu & 1 == 0 and nu % 3 == 0:\n",
    "                ans += nu\n",
    "                cnt += 1\n",
    "            \n",
    "        return ans // cnt if cnt != 0 else 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        l=[]\n",
    "        for i in nums:\n",
    "            if i>=3 and i%6==0 :\n",
    "                l.append(i)\n",
    "        if len(l)==0:\n",
    "            return 0   \n",
    "        return int(sum(l)/len(l))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        total = 0\n",
    "        k = 0\n",
    "        for a in nums:\n",
    "            if a % 6 == 0:\n",
    "                total += a\n",
    "                k += 1\n",
    "        return total // k if k > 0 else 0\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        c, s = 0, 0\n",
    "        for n in nums:\n",
    "            if n % 2 == 0 and n % 3 == 0:\n",
    "                c += 1\n",
    "                s += n\n",
    "        return s // c if c > 0 else 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        ans,cnt=0,0\n",
    "        for num in nums:\n",
    "            if num%6==0: \n",
    "                ans+=num\n",
    "                cnt+=1\n",
    "        return int(ans/cnt) if cnt>0 else 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        list1=[]\n",
    "        result=0\n",
    "        for i in nums:\n",
    "            if i % 6 == 0:\n",
    "                list1.append(i)\n",
    "            else:\n",
    "                pass\n",
    "        if len(list1)==0:\n",
    "            return len(list1)\n",
    "        else:\n",
    "            for j in list1:\n",
    "                result+=j\n",
    "            return int(result/len(list1))\n",
    "                \n",
    "                    \n",
    "               \n",
    "                    \n",
    "            \n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        result=[i for i  in nums if i%2==0 and i%3==0]\n",
    "        if(len(result)>0) :\n",
    "              avg=sum(result)/len(result)\n",
    "        else:\n",
    "               avg=0      \n",
    "        return int(avg)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        ans = []\n",
    "        for num in nums:\n",
    "            if num % 3 == 0 and num % 2 == 0:\n",
    "                ans.append(num)\n",
    "        return sum(ans) // len(ans) if ans else 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        j=0\n",
    "        sum1=0\n",
    "        for i in nums:\n",
    "            if i%6==0:\n",
    "                j+=1\n",
    "                sum1+=i\n",
    "        return 0 if j==0 else sum1//j"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        list1=list(filter(lambda x:x%3==0 and x%2==0,nums))\n",
    "        r=sum(list1)\n",
    "        if len(list1)==0:\n",
    "            return 0\n",
    "        else:\n",
    "            return int(r/len(list1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        even_list = [] \n",
    "        for i in nums:\n",
    "            if i % 6 == 0:\n",
    "                even_list.append(i)\n",
    "        if even_list:\n",
    "            return int(sum(even_list) / len(even_list))\n",
    "        else:\n",
    "            return 0\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        s = n = 0\n",
    "        for x in nums:\n",
    "            if x % 6 == 0:\n",
    "                s += x\n",
    "                n += 1\n",
    "        return 0 if n == 0 else s // n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        sum1=0\n",
    "        j=0\n",
    "        for num in nums:\n",
    "            if num%6==0:\n",
    "                sum1+=num\n",
    "                j+=1\n",
    "        if j==0:\n",
    "            return 0\n",
    "        else:\n",
    "            return int(sum1/j)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        ans = []\n",
    "        for x in nums:\n",
    "            if x % 3 == 0 and x % 2 == 0:\n",
    "                ans.append(x)\n",
    "        n = len(ans)\n",
    "        if n == 0:\n",
    "            return 0\n",
    "        return sum(ans) // n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        count=0\n",
    "        sum=0\n",
    "        for x in enumerate(nums):\n",
    "          if x[1]%3==0 and x[1]%2==0:\n",
    "              count+=1\n",
    "              sum+=x[1]\n",
    "        if count==0:\n",
    "            return 0\n",
    "        return (int)(sum/count)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        return sum(num for num in nums if num % 2 == 0 and num % 3 == 0) // sum(1 for num in nums if num % 2 == 0 and num % 3 == 0) if any(num % 2 == 0 and num % 3 == 0 for num in nums) else 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        result = 0\n",
    "        count = 0\n",
    "        for i in nums:\n",
    "            if i % 2 == 0 and i % 3 == 0:\n",
    "                result += i\n",
    "                count += 1\n",
    "        if count == 0:\n",
    "            return 0\n",
    "        return result // count\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        count = 0\n",
    "        sum = 0\n",
    "        for i in nums:\n",
    "            if i % 6 == 0:\n",
    "                sum += i\n",
    "                count += 1\n",
    "        if count == 0:\n",
    "            return 0\n",
    "        return int(sum/count)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        p  = []\n",
    "        for x in nums:\n",
    "            if x % 6 == 0:\n",
    "                p.append(x)\n",
    "        return sum(p)//len(p) if p else 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        num = [num for num in nums if num % 6 ==0]\n",
    "        return sum(num) // len(num)  if num else 0\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        ans,count = 0,0\n",
    "        for num in nums:\n",
    "            if num%2==0 and num%3==0:\n",
    "                ans += num\n",
    "                count += 1\n",
    "        return ans//count if count>0 else ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        ans=0\n",
    "        k=0\n",
    "        for n in nums:\n",
    "            if n%6==0:\n",
    "                ans+=n\n",
    "                k+=1\n",
    "        if k:\n",
    "            return ans//k\n",
    "        return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        a=0\n",
    "        list1=[]\n",
    "        for i in range(0,len(nums)):\n",
    "            if nums[i]%6==0:\n",
    "                a=a+nums[i]\n",
    "                list1.append(nums[i])\n",
    "        b=len(list1)\n",
    "        if b==0:\n",
    "            y=0\n",
    "        else:\n",
    "            y=a//b\n",
    "        return y\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        n = 0\n",
    "        s = 0\n",
    "        for i in range(len(nums)):\n",
    "            if nums[i] % 6 == 0:\n",
    "                s += nums[i]\n",
    "                n += 1\n",
    "        if n == 0 : \n",
    "            return 0\n",
    "        else:\n",
    "            return s // n\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        s=0\n",
    "        count=0\n",
    "        for i in nums:\n",
    "            if i%6==0:\n",
    "                s+=i\n",
    "                count+=1\n",
    "        if count==0:\n",
    "            return 0\n",
    "        else:\n",
    "            return s//count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        res = 0\n",
    "        count = 0\n",
    "        for num in nums:\n",
    "            if num % 2 == 0 and num % 3 == 0:\n",
    "                res += num\n",
    "                count += 1\n",
    "        if count == 0:\n",
    "            return 0\n",
    "        return math.floor(res / count)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        total = 0\n",
    "        k = 0\n",
    "        for a in nums:\n",
    "            if a % 6 == 0:\n",
    "                total += a\n",
    "                k += 1\n",
    "        return total // k if k > 0 else 0\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        s = n = 0\n",
    "        for x in nums:\n",
    "            if x%6 ==0:\n",
    "                s += x\n",
    "                n += 1\n",
    "        return 0 if n == 0 else s//n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        temp = 0\n",
    "        n = 0\n",
    "        for i in nums:\n",
    "            if i % 6 == 0:\n",
    "                temp += i\n",
    "                n += 1\n",
    "        return temp // n if n else 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "      sum_ = 0\n",
    "      count = 0\n",
    "      for num in nums:\n",
    "        if num % 3 == 0 and num % 2 == 0:\n",
    "          sum_ += num\n",
    "          count += 1\n",
    "\n",
    "      if count > 0:\n",
    "        mean = sum_ // count\n",
    "        return mean\n",
    "      else:\n",
    "        return 0\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        #cnt = 0\n",
    "        #for i in nums:\n",
    "            #for j in nums:\n",
    "                #if i % 6 == 0 and j % 6 == 0 and i != j:\n",
    "                    #return (i + j) // 2\n",
    "                    #return 0\n",
    "        s = n = 0\n",
    "        for x in nums:\n",
    "            if x % 6 == 0:\n",
    "                s += x\n",
    "                n += 1\n",
    "        return 0 if n == 0 else s // n\n",
    "            \n",
    "                \n",
    "                        \n",
    "                    \n",
    "                        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        ans=0\n",
    "        count=0\n",
    "        for num in nums:\n",
    "            if not num%3 and not num%2:\n",
    "                ans+=num\n",
    "                count+=1\n",
    "        if count==0:\n",
    "            return 0\n",
    "        return ans//count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        def is3(n):\n",
    "            res=0\n",
    "            while n: \n",
    "                res+=n%10\n",
    "                n//=10\n",
    "            return res%3==0\n",
    "\n",
    "        tmp=[n for n in nums if n&1==0 and is3(n)]\n",
    "        return sum(tmp)//len(tmp) if tmp else 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        ans = 0\n",
    "        index = 0\n",
    "        for num in nums:\n",
    "            if num % 3 == 0 and num % 2 == 0:\n",
    "                ans += num\n",
    "                index += 1\n",
    "        if index == 0:\n",
    "            return 0\n",
    "        return ans // index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        ns = [x for x in nums if x % 6 == 0]\n",
    "        return 0 if len(ns) == 0 else sum(ns) // len(ns)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        total = 0\n",
    "        k = 0\n",
    "        for a in nums:\n",
    "            if a % 6 == 0:\n",
    "                total += a\n",
    "                k += 1\n",
    "        return total // k if k > 0 else 0\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:       \n",
    "        tmp=[n for n in nums if n&1==0 and n%3==0]\n",
    "        return sum(tmp)//len(tmp) if tmp else 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        totalnum = 0\n",
    "        cntnum = 0\n",
    "        for num in nums:\n",
    "            if num % 6 == 0:\n",
    "                totalnum += num\n",
    "                cntnum += 1\n",
    "        if cntnum == 0:\n",
    "            return 0\n",
    "        else:\n",
    "            return totalnum // cntnum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        nums = [x for x in nums if x % 6 == 0]\n",
    "        return 0 if not len(nums) else sum(nums) // len(nums)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        even = []\n",
    "        for num in nums:\n",
    "            if num % 6 == 0:\n",
    "                even.append(num)\n",
    "        if even == []:\n",
    "            return 0\n",
    "        return sum(even)//len(even)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        amount=0\n",
    "        count=0\n",
    "        n=len(nums)\n",
    "        for i in range(n):\n",
    "            if nums[i]%3==0 and nums[i]%2==0:\n",
    "                amount+=nums[i]\n",
    "                count+=1\n",
    "        if count:\n",
    "            avg=amount//count\n",
    "            return avg\n",
    "        else:\n",
    "            return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        aaa = [i for i in nums if i%6==0]\n",
    "        return 0 if len(aaa) == 0 else int(sum(aaa)/len(aaa))\n",
    "\n",
    "        # aaa = []\n",
    "        # for i in nums:\n",
    "        #     if i%2 == 0:\n",
    "        #         aaa.append(i)\n",
    "\n",
    "        # bbb = []\n",
    "        # for i in aaa:\n",
    "        #     if i%3 == 0:\n",
    "        #         bbb.append(i)\n",
    "\n",
    "        # if len(bbb) == 0:\n",
    "        #     return 0\n",
    "        # else:\n",
    "        #     result = int(sum(bbb)/len(bbb))\n",
    "        #     return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        s = num = 0\n",
    "        for n in nums:\n",
    "            if n % 6: continue\n",
    "            s += n\n",
    "            num += 1\n",
    "        return s // num if num else 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        list_1 = []\n",
    "        add = 0\n",
    "        for i in range(len(nums)):\n",
    "            if nums[i] % 2 == 0 and nums[i] % 3 == 0:\n",
    "                list_1.append(nums[i])\n",
    "        for j in list_1:\n",
    "            add += j\n",
    "        if len(list_1) == 0:\n",
    "            return 0\n",
    "        else:\n",
    "            return int(add / len(list_1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        cnt=0\n",
    "        res=0\n",
    "        for i in nums:\n",
    "            if i%6==0:\n",
    "                cnt+=1\n",
    "                res+=i\n",
    "        if cnt ==0:\n",
    "            return 0\n",
    "        else:\n",
    "            return math.floor(res /cnt)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        sum1 = 0\n",
    "        count = 0\n",
    "        for i in nums:\n",
    "            if i % 2 == 0 and i % 3 == 0:\n",
    "                sum1 += i\n",
    "                count += 1\n",
    "        if count == 0:\n",
    "            return 0\n",
    "        return sum1 // count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        sum =0\n",
    "        step=0\n",
    "        for i in nums:\n",
    "            if i%6==0:\n",
    "                sum+=i\n",
    "                step+=1\n",
    "            else:\n",
    "                pass\n",
    "        if step ==0:\n",
    "            return 0\n",
    "        else:\n",
    "            return int(sum/step )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        sum_num = 0\n",
    "        count = 0\n",
    "        for i in nums:\n",
    "            if i % 3 == 0 and i % 2 == 0:\n",
    "                sum_num += i\n",
    "                count += 1\n",
    "        if count == 0:\n",
    "            return 0\n",
    "        return int(sum_num / count)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        temp = 0\n",
    "        n = 0\n",
    "        for num in nums:\n",
    "            if num % 2 ==0 and num % 3==0: \n",
    "                temp += num\n",
    "                n += 1\n",
    "        if n== 0:\n",
    "            return 0\n",
    "        return int(temp / n )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        ans = 0\n",
    "        count = 0\n",
    "        amount = 0\n",
    "        for x in nums:\n",
    "            if x % 6 == 0:\n",
    "                count += 1\n",
    "                amount += x\n",
    "        if count != 0:\n",
    "            ans = int(amount / count)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def averageValue(self, nums: List[int]) -> int:\n",
    "        total = 0\n",
    "        cnt = 0\n",
    "        for n in nums:\n",
    "            if n % 6 == 0:\n",
    "                total += n\n",
    "                cnt += 1\n",
    "        if cnt > 0:\n",
    "            return total // cnt\n",
    "        return cnt\n",
    "        "
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
